<template>
	<div class="followupNotice">
		<tmpHeader :index="3"/>
		<br />
		<div>
			<Button type="info" @click='addFollow' >
				<i class = "iconfont icon-add icon" ></i>
			</Button>
		</div>
		<br />
		<Table stripe :columns="columns1" :data="data1"></Table>
		<div class="page">
            <Page :total="count" :current='pageNo' :page-size="pageSize" show-total show-elevator @on-change="pageChange"/>
        </div>
		<div  class="btn" @click="back">
			<Button>
				<i class = "iconfont icon-butongyi icon" ></i>返回
			</Button>
		</div>		
	</div>
</template>
<script>
import tmpHeader from "../tmpHeader";
import api from "@/api/commonApi";
import code from "@/configs/base.js";
import vueEditor from "@/components/vueEditor";
import aesUtils from "@/plugins/aes-utils.js";
import store from "@/store";
export default {
	components: {
		tmpHeader,
		vueEditor
	},
	data() {
		return {
			urlCode: '{"urlCode":"' + code.urlCode.richText + '"}',
			pageNo: 1,
			pageSize: 10,
			count: 10,
			id: sessionStorage.getItem("hospitalId"),
			columns1: [
				{
					title: "排序",
					key: "isum",
					align: "center"
				},
				{
					title: "协议标题",
					key: "protocolName",
					align: "center"
				},
				{
					title: "协议类型",
					key: "protocolType",
					align: "center"
				},
				{
					title: "状态(是否启用)",
					key: "protocolStatus",
					align: "center"
				},
				{
					title: "设置",
					align: "center",
					render: (h, params) => {
						let row = params.row;
						return [
							h(
								"a",
								{
									on: {
										click: () => {
											this.change(row)
										}
									}
								},
								"编辑"
							)
						];
					}
				}
			],
			data1: [],
		};
	},
	created () {
		this.nick = this.$route.query.nick;
		let iv = store.state.iv;
		let salt = store.state.salt;
		this.appid = aesUtils.decrypt(salt,iv,"wxAppid",localStorage.getItem("appid"))
		let breadList = [
			{ path: "/index", title: "首页" },
			{
				path: "/index/publicOperation/publicAddress/home",
				title: "公众号运营"
			}
		];
		this.$emit("changeBreadList", breadList);
	},
	mounted () {
		this.loadingData(1)
	},
	methods: {
		// 点击编辑
		change(item) {
			this.functionJS.queryNavgationTo(this,'/index/publicOperation/publicAddress/protocol/edit',{
				id: item.id,pageNo:this.pageNo,txt:'协议文案编辑',nick:this.nick
			})
		},
		pageChange(index) {
			this.loadingData(index)
		},
		// 添加协议按钮
		addFollow () {
			this.functionJS.queryNavgationTo(this,'/index/publicOperation/publicAddress/protocol/edit',{pageNo:this.pageNo,txt:'协议文案新增',nick:this.nick})
		},	
		//获取协议列表
		loadingData (pageNo) {
			let url = api.findWxProtocolList
			let params = {
				pageNo,
				pageSize: this.pageSize,
				appid: this.appid,
			}
			this.pageNo = pageNo;
			this.$axios.post(url, params).then(res => {
				if(res.data.success) {
					let ret = res.data.object;
					ret.records.forEach((item,index) => {
						item.isum = this.addZeros(index)
						item.protocolStatus = item.protocolStatus == 1 ? "是" :"否" 
						if(item.protocolType == 1){
						item.protocolType = '注册协议'
						}
					})
					this.data1 = ret.records
					this.count = ret.total
				} else {
					this.$Message.error('查询协议列表失败')
				}
			})
		},
		back() {
			this.functionJS.queryNavgationTo(this,'/index/publicOperation/publicAddress/home',{pageNo:this.pageNo})
		},
	}
};
</script>
<style lang="less" scoped>
.followupNotice {
	width: 100%;
	padding: 10px 30px;
	margin: 0 auto;
	background: #fff;
	.page{
        text-align: center;
        margin: 20px 0;
    }
	.icon{
		margin-right: 5px;
		font-size: 14px;
	}
	.btn{
		text-align: center;
	}
}
</style>
